!function(window){
	if (!Array.prototype.indexOf){
		  Array.prototype.indexOf = function(elt /*, from*/){
		    var len = this.length >>> 0;

		    var from = Number(arguments[1]) || 0;
		    from = (from < 0)
		         ? Math.ceil(from)
		         : Math.floor(from);
		    if (from < 0)
		      from += len;

		    for (; from < len; from++){
		      if (from in this && this[from] === elt)
		        return from;
		    }
		    return -1;
		  };
		}
	var HTMLTurbo=function(selector){
	}
	HTMLTurbo.util={};
	HTMLTurbo.module={};
	HTMLTurbo.page={};
	HTMLTurbo.control={}
	
	HTMLTurbo.prototype.context=".ht ";
	HTMLTurbo.prototype.controlList=new Array();
	HTMLTurbo.prototype.maxControlId=10000;
	HTMLTurbo.prototype.frameWindowArray=new Array();
	HTMLTurbo.prototype.focusFrameWindow=null;
	HTMLTurbo.prototype.inited=false;
	HTMLTurbo.prototype.console=null;
	HTMLTurbo.prototype.init=function(){
		if(this.inited==false){
			this.inited=true;
			this.update(".ht");
		}
		//this.console=new Console();
	}
	HTMLTurbo.prototype.update=function(context){
		if(typeof context!="undefined"){
			this.context=context;
		}else{
			this.context=".ht "
		}
		//console.log(context);
		this.updateConsole();
		this.updateA();
		this.updateInput();
		this.updateSelect();
		this.updateIframe();
		this.updateTable();
		
		this.updateMasker();
		this.updateLoading();
		
		this.updateBirdge();
		
		this.updateAutoDialog();
		this.updateAutoFrameWindow();
		
		this.updateControls(this.context);
		
		ht.loading.close()
	}
	HTMLTurbo.prototype.updateConsole=function(){
		if(typeof(console)=="undefined"){
			window.console=function(){}
			window.console.log=function(object){}
		};
		this.console=new Console();
	}
	HTMLTurbo.prototype.updateControls=function(context){
		var selectors=$("[data-ht-control]",context)
		for(var i=0;i<selectors.length;i++){
			this.createControl(selectors.eq(i))
		}
	}
	HTMLTurbo.prototype.createControl=function(selector,className){
		if(typeof className=="undefined"){
			var className=$(selector).attr("data-ht-control");
		}
		var options=$(selector).attr("data-ht-options");
		//console.log(className);
		var evalStr="new HTMLTurbo.control."+className+"(selector,options)";
		var control=eval(evalStr);
		control.init();
		this.appendControl(control);
		return control;
	}
	HTMLTurbo.prototype.appendControl=function(control){
		this.maxControlId++;
		var htid="ht"+this.maxControlId;
		control.setId(htid);
		this.controlList.push(control);
	}
	HTMLTurbo.prototype.getControl=function(selector){
		var htid=$(selector).eq(0).attr("data-ht-id");
		var control=null;
		console.log(this.controlList);
		for(var i=0;i<this.controlList.length;i++){
			if(this.controlList[i].id==htid){
				control=this.controlList[i]
				break;
			}
		}
		return null;
	}
	
	HTMLTurbo.prototype.getTabs=function(selector){
		var className="Tabs";
		var control=this.getControl(selector);
		if(control==null){
			control=this.createControl(selector,className);
		}
		return control
	}
	
	//A
	HTMLTurbo.prototype.updateA=function(){
		var total
		var i=0;
		var selectors=$("a",this.context);
		var a=null;
		total=selectors.length;
		for(i=0;i<total;i++){
			this.createControl(selectors.eq(i),"A");
		}
	}
	//Input
	HTMLTurbo.prototype.updateInput=function(){
		var selectors=$("input",this.context);
		var total=selectors.length;
		
		var selector=null;
		var type=''
		var list="";
		var input=null;
		for(var i=0;i<total;i++){
			selector=selectors.eq(i);
			type=selector.attr("type");
			list=selector.attr("list");
			if(type=="int"){
				this.createControl(selector,"IntInput");
				continue;
			}
			if(type=="number"){
				this.createControl(selector,"NumberInput");
				continue;
			}
			if(type=="date"){
				this.createControl(selector,"DateInput");
				continue;
			}
			if(type=="time"){
				this.createControl(selector,"TimeInput");
				continue;
			}
			if(type=="text"){
				this.createControl(selector,"TextInput");
				continue;
			}
		}
	}
	//Select
	HTMLTurbo.prototype.updateSelect=function(){
		var selectors=$("select",this.context)
		var total=selectors.length;
		for(var i=0;i<total;i++){
			var selector=selectors.eq(i);
			this.createControl(selector,"Select");
		}
	}
	//IFrame
	HTMLTurbo.prototype.updateIframe=function(){
		var selectors=$("iframe",this.context)
		var total=selectors.length;
		for(var i=0;i<total;i++){
			var selector=selectors.eq(i);
			this.createControl(selector,"Iframe");
		}
	}
	//IFrame
	HTMLTurbo.prototype.updateTable=function(){
		var selectors=$("table",this.context)
		var total=selectors.length;
		for(var i=0;i<total;i++){
			var selector=selectors.eq(i);
			this.createControl(selector,"Table");
		}
	}
	//Masker
	HTMLTurbo.prototype.updateMasker=function(){
		var selector=".ht-Masker";
		var masker=this.createControl(selector,"Masker");
		this.masker=masker;
	}
	
	//Loading
	HTMLTurbo.prototype.updateLoading=function(){
		var selector=".ht-Loading";
		var loading=this.createControl(selector,"Loading");
			loading.setMasker(this.masker);
		this.loading=loading;
	}
	
	//Birdge
	HTMLTurbo.prototype.updateBirdge=function(){
		this.createControl(undefined,"Birdge");
	}
	
	
	
	//Dialog
	HTMLTurbo.prototype.updateAutoDialog=function(){
		var selectors=$(".ht-Dialog.auto",this.context)
		var self=this;
		selectors.each(function(index, selector) {
			self.createControl(selector,"Dialog");
	    });
	}
	
	HTMLTurbo.prototype.openDialog=function(selector){
		//var dialog=new HTMLTurbo.control.Dialog(selector);
		var control=this.createControl(selector,"Dialog");
		return control;
	}
	//frameWindow
	HTMLTurbo.prototype.updateAutoFrameWindow=function(){
		var self=this;
		var selectors=$(".ht-Popup.frame.auto",this.context)
		selectors.each(function(index, selector) {
	       	var href=$(selector).attr("href");
		    var frameWindow=self.openFrameWindow(href,"","");
			self.setFocusFrameWindow(frameWindow);
	    });
	}
	HTMLTurbo.prototype.openFrameWindow=function(url,title,size){
		/*var option={
			window:top,
			className:fullScreen,
			title:title,
			url:url
		}*/
		//var frameWindow=new HTMLTurbo.control.FrameWindow();
		var frameWindow=this.createControl(undefined,"FrameWindow");
		frameWindow.open(url,title,size);
		this.frameWindowArray.push(frameWindow);
		
		this.setFocusFrameWindow(frameWindow);
		return frameWindow;
	}
	HTMLTurbo.prototype.setFocusFrameWindow=function(focusFrameWindow){
		this.focusFrameWindow=focusFrameWindow;
	}
	HTMLTurbo.prototype.hideAllFrameWindow=function(){
		var frameWindowArray=this.frameWindowArray
		var total=frameWindowArray.length;
		for(var i=0;i<total;i++){
			frameWindowArray[i].hide();
		}
		return false;
	}
	HTMLTurbo.prototype.closeAllFrameWindow=function(){
		var frameWindowArray=this.frameWindowArray
		var total=frameWindowArray.length;
		for(var i=0;i<total;i++){
			frameWindowArray[i].close();
		}
		return false;
	}
	HTMLTurbo.prototype.closeFocusFrameWindow=function(){
		this.focusFrameWindow.close();
	}
	{content}
	window.HTMLTurbo=window.HT=HTMLTurbo;
}(window)

var htmlTurbo=new HTMLTurbo();
var ht=htmlTurbo;

//自定义控制台
ht.console=new HTMLTurbo.control.Console();